import {
  listAllTableColumn,
  listByPage,
  listAllTableData,
  listAllTableColumn4Office,
  batchDeletion,
  oneClickDelete,
  insertOfficeInfo,
  deleteById,
  findById, updateRecord,
  getPageData,
  findDataById,
  exportSysteminitImportInfo,
  queryAllExportData
} from '@/services/initialdatareportingApi';

export default {
  namespace: 'initialdatareporting',

  state: {
    // 初始数据上报
    data: {
      list: [],
      pagination: {},
    },
    // 初始数据正式库
    data2: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *listByPage({ payload }, { call, put }) {
      const response = yield call(listByPage, payload);
      yield put({
        type: 'cb4listAllByPage',
        payload: response,
      });
    },
    /**
     * 获取table的columns
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllTableColumn({ payload }, { call, put }) {
      const response = yield call(listAllTableColumn, payload);
      return response;
    },

    /**
     * 点击批量删除
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *batchDeletion({ payload }, { call, put }) {
      const response = yield call(batchDeletion, payload);
      return response;
    },

    /**
     * 点击一键删除
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *oneClickDelete({ payload }, { call, put }) {
      const response = yield call(oneClickDelete, payload);
      return response;
    },

    /**
     * 点击存入正式库
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *insertOfficeInfo({ payload }, { call, put }) {
      const response = yield call(insertOfficeInfo, payload);
      return response;
    },

    /**
     * 获取table的columns
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllTableColumn4Office({ payload }, { call, put }) {
      const response = yield call(listAllTableColumn4Office, payload);
      return response;
    },

    /**
     * 删除单条数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *deleteById({ payload }, { call, put }) {
      const response = yield call(deleteById, payload);
      return response;
    },

    /**
     * 查询单条数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *findById({ payload }, { call, put }) {
      const response = yield call(findById, payload);
      return response;
    },

    /**
     * 更新数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *updateRecord({ payload }, { call, put }) {
      const response = yield call(updateRecord, payload);
      return response;
    },

    /**
     * 获取列表数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllTableData({ payload }, { call, put }) {
      const response = yield call(listAllTableData, payload);
      yield put({
        type: 'cb4listAllTableData',
        payload: response,
      });
    },

    /**
     * 获取分页正式库列表数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     * */
    *getPageData({ payload }, { call, put }) {
      const response = yield call(getPageData, payload);
      yield put({
        type: 'cb4getPageData',
        payload: response,
      });
    },

    /**
     * 获取单条
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     * */
    *findDataById({ payload }, { call, put }) {
      const response = yield call(findDataById, payload);
      return response;
    },

    /**
     * 文件选中下载
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     * */
    *exportSysteminitImportInfo({ payload }, { call, put }) {
      const response = yield call(exportSysteminitImportInfo, payload);
      return response;
    },

    /**
     * 初始数据正式库的默认导出全部
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     * */
    *queryAllExportData({ payload }, { call, put }) {
      const response = yield call(queryAllExportData, payload);
      return response;
    }
  },

  reducers: {
    cb4listAllByPage(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    cb4getPageData(state, action) {
      return {
        ...state,
        data2: action.payload.data,
      };
    },
    cb4listAllTableData(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
